<?php

namespace App\Admin\Controllers;

use App\Models\Tcmclassic;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TcmclassicController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Tcmclassic(), function (Grid $grid) {
            $grid->model()->with(['jump'])->orderByDesc('id');

            $grid->column('id')->sortable();
//            $grid->column('module');
            $grid->column('name');
//			$grid->column('url');
            $grid->column('jump.name', '跳转标签名称');
			$grid->column('sort')->editable(true);
			$grid->column('status')->switch();
			$grid->column('images')->image('',50,50);
            //$grid->column('created_at');
            //$grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Tcmclassic(), function (Show $show) {
            $show->field('id');
            $show->field('module');
            $show->field('name');
			$show->field('name');
			$show->field('status');
			$show->field('sort');
			$show->field('images')->image('',50,50);
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Tcmclassic(), function (Form $form) {
            $form->display('id');
//            $form->text('module');
            $form->text('name');

//			$form->text('url');
            $form->select('jump_tag_id', '跳转标签')->options(\App\Models\JumpTag::where('is_show', 1)->pluck('name', 'id')->all())->required();
			$form->image('images')->uniqueName()->autoUpload()->saveFullUrl();
			$form->number('sort');
			$form->select('status')->options(['0'=>'关闭','1'=>'显示'])->default('0');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
